<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>地震局培训平台</title>
	<link rel="stylesheet" href="style/exam.css" />
</head>

<body>
	<div id="show">
		<div class="title"></div>
		<div class="list">
			<!-- <div class="box">
				<div class="text">地震时的相对安全场所为那些？</div>
			</div>
			<div class="box">
				<div class="text">地震应急测试（一）</div>
			</div>
			<div class="box">
				<div class="text">地震时的相对安全场所为那些？</div>
			</div>
			<div class="box">
				<div class="text">地震应急测试（一）</div>
			</div>
			<div class="box">
				<div class="text">地震时的相对安全场所为那些？</div>
			</div> -->
		</div>
		<div class="pagebox">
			<div class="pageborder" style="top: 690px;"></div>
			<div class="numbox" style="top: 690px;">
				<!--<div class="page">1</div>
					<div class="page in">2</div>
					<div class="page">3</div>-->
			</div>
		</div>
		<!--<div class="submit"></div>-->
	</div>

	<script type="text/javascript" src="script/jquery.min.js"></script>
	<script type="text/javascript" src="script/ishoock.tools.js"></script>
	<script>
		$(function () {
			getList();

			$(document).on('click', '.box', function () {
				var index = $(".box").index(this);

				var examId = $(".box").data("result")[index].examId;
				console.log(examId);
				// window.location.href("exam2.html" +"?value="+ examId);
				window.location.href = "exam2.html" + "?value=" + examId;
			});

			//点击页数
			$(".left .numbox").on("click", ".page", function () {
				page = parseInt($(event.target).attr("data-id"));
				$(".left .numbox .page").removeIn();
				$(event.target).in();
				pageClick(page);
			})
			// $(".box").on("click", function () {
			// 	window.location.href = "exam2.html";
			// });
		});
		function getList() {
			$.ajax({
				type: "GET",
				url: "http://101.201.113.151:9230/traning/getExaminationList", //访问的链接
				data: {
					pageSize: 10,
					page: page
				},
				dataType: "json",  //数据格式设置为jsonp
				// jsonp:"callback",
				async: true,
				success: function (data) {  //成功的回调函数
					$(".left .list").empty();
					allpage = data.allpage;
					prevpage = data.prev;
					nextpage = data.next;
					if (isLoad) {
						Page();
					}
					var data = data.result;
					var Length;
					if (page * 10 < data.length) {
						Length = page * 10;
					} else {
						Length = data.length;
					}
					var I = (page - 1) * 10;
					// console.log(data);
					for (var i = I; i < Length; i++) {
						var item = '<div class="box">' +
							'<div class="text">' + data[i].title + '</div>' +
							'</div>';
						$(".list").append(item);
						$(".box").data("result", data.result);
					}
				},
				error: function (e) {
				}
			});
		}
		var page = 1;//当前页数
		var allpage, prevpage, nextpage, isLoad = true;
		//加载页数
		function Page() {
			isLoad = false;
			var i_page;
			if (allpage > 3) {
				i_page = 3;
			} else {
				i_page = allpage;
			}
			for (var i = 0; i < i_page; i++) {
				var item = '<div class="page" data-id="' + (i + 1) + '">' + (i + 1) + '</div>';
				$(".pagebox .numbox").append(item);
				$(".pagebox .numbox").children().eq(0).in();
			}
		}

		//点击页数
		function pageClick(n) {
			if (n <= allpage) {
				if ((n + 1) <= allpage) {
					$(".pagebox .numbox").children().eq(0).remove();
					var item = '<div class="page" data-id="' + (n + 1) + '">' + (n + 1) + '</div>';
					$(".pagebox .numbox").append(item);
				}
				getList();
			}
		}
	</script>
</body>

</html>